package com.egg.ylt.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.egg.ylt.R;
import com.egg.ylt.Utils.GlideUtils;
import com.egg.ylt.pojo.DiaryPhotoEntity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * sichaoqi on 2018/12/18
 */
public class ADA_LookBigPictrue extends RecyclerView.Adapter<ADA_LookBigPictrue.LookViewHolder> {


    private Context mContext;
    private LayoutInflater mInflater;
    private List<DiaryPhotoEntity.ListBean.DateListBean> mDataList;

    public ADA_LookBigPictrue(Context context) {
        this.mContext = context;
        mInflater = LayoutInflater.from(mContext);
        mDataList = new ArrayList<>();
    }

    public void setDataList(List<DiaryPhotoEntity.ListBean.DateListBean> list) {
        if (mDataList != null) {
            mDataList.clear();
        }
        mDataList.addAll(list);
        notifyDataSetChanged();
    }

    @Override
    public LookViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new LookViewHolder(mInflater.inflate(R.layout.item_img_view, parent, false));
    }

    @Override
    public void onBindViewHolder(LookViewHolder holder, int position) {
        DiaryPhotoEntity.ListBean.DateListBean dateListBean = mDataList.get(position);
        //加载图片
//        GlideUtils.showImageView(mContext, R.mipmap.ic_banner_default, dateListBean.getUrl(), holder.ivImg);
        Glide.with(mContext).load(dateListBean.getUrl()).fitCenter().into(holder.ivImg);
    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    static class LookViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.iv_img)
        ImageView ivImg;
        public LookViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
